/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package entity;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Alessandro
 */
@Entity
public class Message implements Serializable {
   private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer messageId;
    @NotNull
    private MessageType type;
    @NotNull
    @Temporal(TemporalType.TIMESTAMP)
    private Date timestamp;
    @Temporal(TemporalType.DATE)
    private Date sugestedDate;
    @JoinColumn(name = "event", referencedColumnName = "id")
    @ManyToOne
    private Event event;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "message1")
    private Collection<SentMessage> sentMessageCollection;

    public Message() {
    }

    public Message(Integer id) {
        this.messageId = id;
    }

    public Message(Integer id, MessageType type, Date time) {
        this.messageId = id;
        this.type = type;
        this.timestamp = time;
    }

    public Integer getMessageId() {
        return messageId;
    }

    public void setMessageId(Integer messageId) {
        this.messageId = messageId;
    }

    public MessageType getType() {
        return type;
    }

    public void setType(MessageType type) {
        this.type = type;
    }

    public Date getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(Date timestamp) {
        this.timestamp = timestamp;
    }

    public Date getSugestedDate() {
        return sugestedDate;
    }

    public void setSugestedDate(Date sugestedDate) {
        this.sugestedDate = sugestedDate;
    }

    public Event getEvent() {
        return event;
    }

    public void setEvent(Event event) {
        this.event = event;
    }

    @XmlTransient
    public Collection<SentMessage> getSentMessageCollection() {
        return sentMessageCollection;
    }

    public void setSentMessageCollection(Collection<SentMessage> sentMessageCollection) {
        this.sentMessageCollection = sentMessageCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (messageId != null ? messageId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the messageId fields are not set
        if (!(object instanceof Message)) {
            return false;
        }
        Message other = (Message) object;
        if ((this.messageId == null && other.messageId != null) || (this.messageId != null && !this.messageId.equals(other.messageId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entity.Message[ id=" + messageId + " ]";
    }
    
}
